home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 51
/
Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso
/
-in_the_mag-
/
program_perfection
/
vbcc
/
mystartup
/
mystart.doc
< prev
next >
Wrap
Text File
|
2000-02-16
|
2KB
|
77 lines
MyStartup
=========
Fairly minimal startup code for the VBCC compiler which still
supports some handy features.
Function
--------
This startup code sets up SYSBase, opens dos.library (no revision
specified) and handles the WBStartup message. If dos.library
cannot be opened, then the code will display a standard alert
then exit, returning a fatal error.
The usual C entry point main is called with different parameters
than usual. A prototype would be:
int main( char *command, int len );
command is a string containing just the arguments passed to your
program NOT the whole command line. len is the length of the
argument string. No parsing is performed on the argument string.
In fact it is probably best to define your main() with no
parameters, that is,
int main( void );
and use the dos.library ReadArgs() routine to parse any
arguments.
The standard exit() function works as per normal. It's parameter is passed
back to DOS as an return code (see dos.h). If you want to return an
error code as well, use SetIoErr().
This startup code handles vlink constructors and destructor (auto
initialization and exit functions) and so auto opening of
libraries via auto.lib still works.
This startup code gets and replies to a Workbench startup
message, so it safe to start your program from the WB. This
message can be found in the global pointer WBenchMsg as per
usual.
All C standard library functions will still work with the
exception of the stdio routines. So, there's no fopen(), fread(),
printf(), etc. Use dos.library equivalents instead.
Rationale
---------
Why go to all this bother? Well, by cutting out the stdio stuff
and the command line parsing, you can shave a couple of thousand
bytes of your executable size. Not much in the big scheme of
things, but what the hell. It's also more elegant when don't
require portability. Why include all that stuff when you're just
gonna use the dos.library calls anyway?
VBCC ships with a extrememly minimal startup module, but that
doesn't support WB, constructors, destructors, etc. This one
makes life easier . . .
Linking
-------
To use this startup code in your own projects, you must remember
to disable the standard one with the -nostdlib switch. This has
the unfortunate side effect of not using the standard linker
libraries as well, so you'll have to include this manually.
Always remember that mystartup.o MUST be the first file in your
list of components.